<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body></body>
<script>
    // 题目： 输入一个字符串，找到第一个不重复字符的下标
    // 输入： 'abcabcde'
    // 输出： 6
    let str = "abcabcde";
    function findFrist(str) {
        if (!str) return -1;
        let arr = str.split("");
        let obj = {};
        arr.forEach((item) => {
            let val = obj[item];
            obj[item] = obj[item] ? val + 1 : 1;
        });
        let result = "";
        Object.keys(obj).some((item) => {
            if (obj[item] === 1) {
                result = item;
                return true;
            }
        });
        return result;
    }
    console.log(findFrist(str));
</script>

</html>